﻿using System;
using System.Diagnostics;
using System.Linq.Expressions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.Logging;
using Solution.Comm.DomainInterfaces;
using Solution.Comm.Extensions;
using Solution.Comm.Uuid;
using Solution.Entity.Entitys;
using Solution.Services.User;
using Web.Models;

namespace Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IUserServices _userServices;
        private readonly IUnitOfWork _unitOfWork;

        private readonly ILogger<HomeController> _logger;

        public HomeController(IUserServices userServices, IUnitOfWork unitOfWork, ILogger<HomeController> logger)
        {
            _userServices = userServices;
            _unitOfWork = unitOfWork;
            _logger = logger;
        }

        public IActionResult Index()
        {
            //_logger.LogInformation(new EventId().Id, new Exception("1"), "");
            int Count = 0;

            Expression<Func<SysUser, bool>> expression = t => true;
            expression = expression.And(t => t.Name.Contains("2"));
            
            //expression = expression.And(t => t.AddedTime >= DateTime.Parse("2018-12-15 00:05:16.308"));
            var c = _userServices.GetPage(1, 20, out Count, expression, u => u.Id, true);
            _userServices.Add();
            _unitOfWork.Commit();

            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}